//
//  ShopTableViewCell.m
//  Youhuiju
//
//  Created by liuovyue on 16/7/27.
//  Copyright © 2016年 yutenys. All rights reserved.
//

#import "ShopTableViewCell.h"


@interface ShopTableViewCell()

//购买数量确定
@property (weak, nonatomic) IBOutlet UIButton *buttonAdd;
//购买数量增加
@property (weak, nonatomic) IBOutlet UIButton *buttonMinus;

//取消购买按钮
@property (nonatomic, strong)UILabel *labelDate;
//时间
@property (nonatomic, strong)UILabel *lableSize;

//添加商品功能的适配
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *buttonSureTop;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *buttonSureWidth;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *buttonSureHeight;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *buttonSureLead;
//商品图片适配
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *imageTop;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *imageLead;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *imageHeight;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *imageWidth;
//商品标题
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *titleTop;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *titleLead;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *titleTrail;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *titleBot;
//商品分类
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *classLead;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *classTop;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *classBot;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *classHeight;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *classTrail;

//商品价钱

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *moneyTrail;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *moneyTop;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *moneyLead;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *moneyHeight;

//商品满减

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *fullCutLead;


@property (strong, nonatomic) IBOutlet NSLayoutConstraint *fullCutWidth;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *fullCutHeight;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *fullCutBot;


//商品满多少减多少
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *fullCutMoneyWidth;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *fullCutMoneyBot;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *fullCutMoneyLead;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *fullCutMoneyTop;



//增加数量按钮

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *addLead;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *addTop;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *addWidth;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *addTrail;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *addHeight;

//购买数量
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *numberTop;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *numberBot;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *numberLead;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *numberTrail;


//减少数量按钮

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *minusTop;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *minusLead;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *minusHeight;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *minusWidth;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *cancelTop;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *cancelLead;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *cancelWidth;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *cancelHeight;

@end


@implementation ShopTableViewCell
//清除通知
- (void)dealloc {
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"buttonAllSure" object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"buttonAllCancel" object:nil];
    
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    
    self.labelclassFication.textColor = [UIColor colorWithHexString:@"737373"];
    self.labelMoney.textColor = [UIColor colorWithHexString:@"ff7836"];
    self.labelFullCut.textAlignment = NSTextAlignmentCenter;
    self.labelFullCut.textColor = [UIColor colorWithHexString:@"ff7836"];
    [self.labelFullCut.layer setMasksToBounds:YES];
    [self.labelFullCut.layer setCornerRadius:8.0];
    [self.labelFullCut.layer setBorderWidth:1.0];
    self.labelFullCut.layer.borderColor = [UIColor colorWithRed:1.0 green:0.6135 blue:0.068 alpha:1.0].CGColor;
    //[UIColor colorWithHexString:@"ff7836"];
    
    self.labelDigtal.textAlignment = NSTextAlignmentCenter;
    
    self.labelSaveMoney.textColor = [UIColor colorWithHexString:@"737373"];
    
    [self.buttonAdd setImage:[UIImage imageNamed:@"ljzzengjia"] forState:UIControlStateNormal];
    [self.buttonMinus setImage:[UIImage imageNamed:@"ljzjianqu"] forState:UIControlStateNormal];
    
    [self.buttonSure setImage:[UIImage imageNamed:@"ljzgouwuchedianji"] forState:UIControlStateNormal];
    [self.buttonCancel setImage:[UIImage imageNamed:@"ljzquxiao"] forState:UIControlStateNormal];
    self.buttonCancel.selected = 1;
    
    
    
    self.buttonSure.alpha = 0;
    self.labelDigtal.text = @"1";
    //选择购买物品按钮的约束
    self.buttonSureTop.constant = 48*FitH;
    self.buttonSureWidth.constant = 19*FitW;
    self.buttonSureHeight.constant = 19*FitH;
    self.buttonSureLead.constant = 8 *FitW;
    //取消按钮
    self.cancelTop.constant = 48*FitH;
    self.cancelLead.constant = 8*FitW;
    self.cancelWidth.constant = 19*FitW;
    self.cancelHeight.constant = 19*FitH;
    
    
    //商品图片的约束
    self.imageTop.constant = 35*FitH;
    self.imageLead.constant = 9*FitW;
    self.imageWidth.constant = 100*FitW;
    self.imageHeight.constant = 99*FitH;
    
    //商品标题的约束
    self.titleBot.constant = 84*FitH;
    self.titleTop.constant = 11*FitH;
    self.titleTrail.constant = 21*FitW;
    self.titleLead.constant = 15*FitW;
    
    
    //分类约束
    self.classTop.constant =10*FitH;
    self.classBot.constant =13*FitH;
    self.classLead.constant = 15*FitW;
    
    
    
    //价钱约束
    self.moneyTop.constant = 13*FitH;
    self.moneyLead.constant = 15*FitW;
    self.moneyHeight.constant = 10*FitH;
    self.moneyTrail.constant = 171*FitW;
    
    //满减约束
    
    self.fullCutBot.constant = 14*FitH;
    self.fullCutWidth.constant = 32*FitW;
    self.fullCutHeight.constant = 16*FitH;
    self.fullCutLead.constant = 12*FitW;
    
    //满减金额约束
    self.fullCutMoneyLead.constant = 6*FitW;
    self.fullCutMoneyTop.constant = 57*FitH;
    self.fullCutMoneyBot.constant = 17*FitH;
    
    //增加按钮
    self.addTop.constant = 26*FitH;
    self.addHeight.constant = 22*FitW;
    self.addTrail.constant = 22*FitW;
    self.addLead.constant = 70*FitH;
    
    //减少按钮
    self.minusTop.constant = 26*FitH;
    self.minusLead.constant = 21*FitW;
    self.minusHeight.constant = 22*FitH;
    self.minusWidth.constant = 22*FitW;
    
    //数量
    self.numberBot.constant = 40*FitH;
    self.numberLead.constant = 17*FitW;
    self.numberTrail.constant = 17*FitW;
    self.numberTop.constant = 28*FitH;
    //添加通知
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(buttonAlpha) name:@"buttonAllSure" object:nil];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(buttonCancelAlpha) name:@"buttonAllCancel" object:nil];

}
//相应通知事件
- (void)buttonAlpha {
    
    self.buttonSure.alpha = 1;
    self.buttonCancel.alpha  = 0 ;
}

- (void)buttonCancelAlpha {
    
    self.buttonCancel.alpha = 1;
    self.buttonSure.alpha = 0;
}

//购买数量减少
- (IBAction)butttonMinusAction:(id)sender {
    
    if (self.numAddBlock) {
        self.numAddBlock();
        
    }
    
    
}
//购买数量增加
- (IBAction)buttonAddAction:(id)sender {
   
    if (self.numCutBlock) {
        self.numCutBlock();
        
    }
    
  
}

- (IBAction)buttonCancelAction:(id)sender {
    

    if (self.cancelBlock) {
        self.cancelBlock(!_buttonCancel.selected);
    }
    
    self.buttonCancel.alpha = 0;
    self.buttonSure.alpha = 1;
}





- (IBAction)buttonSureAction:(id)sender {
    
    
    if (self.sureBlock) {
        self.sureBlock(!_buttonSure.selected);
    }
    
    
    self.buttonSure.alpha = 0;
    self.buttonCancel.alpha = 1;
    
    
}

- (void)addModel:(ModelShop *)model {
    self.imageCommodity.image = model.image;
    self.labelTitle.text = model.nameStr;
    self.labelMoney.text = [NSString stringWithFormat:@"￥ %@", model.price];
    self.labelDate.text = model.dateStr;
    self.labelDigtal.text = [NSString stringWithFormat:@"%ld",(long)model.number];
    
    self.buttonCancel.selected = self.isSelected;
    self.lableSize.text = model.sizeStr;
    
    
}





- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
